package m1;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        //连接 140 服务器
        ConnectionFactory f = new ConnectionFactory();
        f.setHost("192.168.64.140"); // wht6.cn
        f.setPort(5672);
        f.setUsername("admin");
        f.setPassword("admin");
        Connection con = f.newConnection(); //连接
        Channel c = con.createChannel();    //通信通道

        //在rabbitmq服务器中，创建队列helloworld
        //如果服务器已经存在这个队列，不会重复创建
        c.queueDeclare("helloworld",false,false,false,null);

        //向 helloworld 队列发送消息
        //任何消息必须转成 byte[] 数组才能发送
        c.basicPublish("", "helloworld", null, "Hello world!".getBytes());

        //断开连接
        c.close();
        con.close();
    }
}
